from django.db.models.signals import post_save, post_init
from django.dispatch import receiver
from .models import FilmSchedule, TicketSeat, MovieHallSeat


@receiver(post_save, sender=FilmSchedule)
def create_seat(sender, instance=None, created=False, **kwargs):
    if created:
        movie_hall = instance.movie_hall
        qs = MovieHallSeat.objects.filter(movie_hall=movie_hall)
        for i in qs:
            TicketSeat.objects.create(movie_hall_seat=i, film_schedule=instance)
        instance.save()

# post_init 只要是有MODEL的任何操作就会有
